package com.ssm.controllor;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ssm.util.qrcode.VerifyCodeUtils;

import sun.net.www.http.HttpClient;


@Controller  
@RequestMapping("/verify")  
public class VerifyCodeController {
	
	final Logger logger = LoggerFactory.getLogger(VerifyCodeController.class);
	
	//访问路径 http://localhost:8080/Util/qrcode/qrcode1
	//页面路径 http://localhost:8080/Util/verify/verifyImage.jsp
	@RequestMapping(value = "verifyImage")
    public void http1(HttpServletRequest request, HttpServletResponse response) throws Exception {

		 	response.setHeader("Pragma", "No-cache");  
	        response.setHeader("Cache-Control", "no-cache");  
	        response.setDateHeader("Expires", 0);  
	        response.setContentType("image/jpeg");  
	        //生成随机字串  
	        String verifyCode = VerifyCodeUtils.generateVerifyCode(4);  
	        //存入会话session  
	        HttpSession session = request.getSession(true);  
	        session.setAttribute("rand", verifyCode.toLowerCase());  
	        //生成图片  
	        int w = 200, h = 80;  
	        VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
    }

}
